from typing import Optional, List
from datetime import datetime

from pydantic import BaseModel, Field


# 文档基础模型
class DocumentBase(BaseModel):
    title: str
    description: Optional[str] = None
    document_type: str
    version: str = "1.0"
    is_latest: bool = True


# 创建文档
class DocumentCreate(DocumentBase):
    project_id: int
    file_path: str
    file_size: int
    mime_type: str
    task_id: Optional[int] = None
    parent_id: Optional[int] = None  # 上一版本文档ID


# 更新文档
class DocumentUpdate(BaseModel):
    title: Optional[str] = None
    description: Optional[str] = None
    version: Optional[str] = None
    is_latest: Optional[bool] = None


# API响应中的文档信息
class DocumentResponse(DocumentBase):
    id: int
    project_id: int
    creator_id: int
    file_path: str
    file_size: int
    mime_type: str
    task_id: Optional[int] = None
    parent_id: Optional[int] = None
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True